/**
 * Author: Shen Yanqiu
 * Date: 2017-12-13
 * Time: 18:24
 *
 */
import modelExtend from 'dva-model-extend';
import { routerRedux } from 'dva/router';
import { token, routerTool } from 'utils';
import { pageModel } from '../common';
import { getWorknoticeList } from './../../services/worknotice';
import { message } from 'antd';

export default modelExtend (pageModel, {
  namespace: 'repository',

  state: {

  },

  subscriptions: {
    setup ({ dispatch, history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === routerTool.getPathByName('Repository')) {
          dispatch({ type: 'getWorknoticeList' });
        }
      });
    },
  },

  effects: {
    // 获取通知列表
    * getWorknoticeList ({ payload = {} }, { call, put }) {
      // console.log(payload);
      const { error, results } = yield call(getWorknoticeList, {
        page: payload.current,
        limit: payload.pageSize,
        // name: payload.name || undefined,
        // dept: payload.dept || undefined,
      });
      // console.log(results);
      if (error === 0 && results) {
        yield put({
          type: 'loadSuccess',
          payload: {
            list: results.list,
            pagination: {
              current: Number(payload.current) || 1,
              pageSize: Number(payload.pageSize) || 10,
              total: results.total,
            },
          },
        });
      }
    },
    * onSeeItemModal ({ payload: id }) {
      console.log('see'+ id.id);
    },
    * onDeleteItemModal ({ payload: {params} }) {
      console.log('delete'+ params.id);
    },
    * searchData({ payload: formData }) {
      console.log(formData);
    },
  },

  reducers: {
    // showList(state, { payload: { data:list }}){
    //   return { ...state, list};
    // }
  },
});
